window.postType ="xml"
function DataCompact(){
	
	this.httpSwitch     	= new HttpSwitch();
	this.httpSwitch.compact = this;
	this.dataSet            = null;
	this.actionName         = ""; 
	
	this.compact        	= null;
	if (!Yacon.isEmpty(window.postType))
	{
		if(window.postType.isEqual("xml"))
			this.compact = new XmlCompact();
		else if(window.postType.isEqual("json"))
			this.compact = new JsonCompact();
	}
}
/**
 * 后台操作对象
 * @param actionName 对象标识
 * @return
 */
DataCompact.prototype.setActionName = function(actionName)
{
	this.actionName = actionName;	
}
/**
 * 同步装载数据局并初始化字段对象
 * @param dataSet 初始化的数据集
 * @param loadMethod 转载函数标识
 * @return
 */
DataCompact.prototype.loadDate = function(dataSet,loadMethod)
{
	if (!dataSet||!loadMethod || loadMethod.isEqual(""))
		return false;
		
	this.dataSet = dataSet;		
	if (this.compact)
	{
		this.compact.setActionName(this.actionName);
		this.compact.setMethodName(loadMethod);
		this.compact.setServiceCode("buss");
		this.compact.setLogID(getLogID(window));
		
		this.load = this.afterLoad;
		this.httpSwitch.isSendSynch = true;		
		this.httpSwitch.send(this.compact.getSwitch(dataSet));
	}			
}

/**
 * 同步式数据交换后处理
 * @return
 */
DataCompact.prototype.afterLoad = function()
{
	this.dataSet.init();
	this.analyzeData(this.httpSwitch.getText());
	
	if (this.compact.resultType.isEqual("1") && this.getResult())
		this.compact.loadDataSet(this.dataSet);
	if (this.compact.resultType.isEqual("2") && this.getResult())
		this.dataSet.dataValue  = this.getDataValue();
}

/**
 * 同步式数据交换
 * @param dataSet 交换的数据集
 * @param switchMethod 交换函数标识
 * @return
 */
DataCompact.prototype.switchDate = function(dataSet,switchMethod)
{
	if (!dataSet||!switchMethod || switchMethod.isEqual(""))
		return false;
		
	this.dataSet = dataSet;		
	if (this.compact)
	{
		this.compact.setActionName(this.actionName);
		this.compact.setMethodName(switchMethod);
		this.compact.setServiceCode("buss");		
		this.compact.setLogID(getLogID(window));
		
		this.load = this.afterSwitch;
		this.httpSwitch.isSendSynch = true;	
		this.httpSwitch.send(this.compact.getSwitch(dataSet));
	}	
}

/**
 * 同步式数据交换后处理
 * @return
 */
DataCompact.prototype.afterSwitch = function()
{
	this.dataSet.init();
	this.analyzeData(this.httpSwitch.getText())
	if (this.compact.resultType.isEqual("1") && this.getResult())
		this.compact.fillDataSet(this.dataSet);
	if (this.compact.resultType.isEqual("2") && this.getResult())
		this.dataSet.dataValue  = this.getDataValue();
	
}
/**
 * 异步式数据交换
 * @param dataSet 交换的数据集
 * @param switchMethod 交换函数标识
 * @return
 */
DataCompact.prototype.refreshData = function(dataSet,switchMethod)
{
	if (!dataSet||!switchMethod || switchMethod.isEqual(""))
		return false;
		
	this.dataSet = dataSet;	
	if (this.compact)
	{
		
		if (window.marquee)
			window.marquee.show();	
	
		if (window.isIE && window.pageLayer)
			window.pageLayer.show();
		
//		if(window.isIE11 && window.pageLayer)
//			window.pageLayer.show();
	
		this.compact.setActionName(this.actionName);
		this.compact.setMethodName(switchMethod);
		this.compact.setServiceCode("refresh");
		
		this.compact.setLogID(getLogID(window));
		
		this.load = this.afterRefresh;
		this.httpSwitch.isSendSynch = false;
		
		this.httpSwitch.send(this.compact.getSwitch(dataSet));
	}
}

/**
 * 异步式数据交换后处理
 * @return
 */
DataCompact.prototype.afterRefresh = function()
{
	if (window.marquee)
		window.marquee.hidden();	
	
	if (window.pageLayer)
		window.pageLayer.hidden();
	
	if (Yacon.isTrue(this.dataSet.getAttribute("isclear")))
		this.dataSet.init();
	else
		this.dataSet.clear();
	
	this.analyzeData(this.httpSwitch.getText())
	if (this.compact.resultType.isEqual("1") && this.getResult())
		this.compact.fillDataSet(this.dataSet);
	if (this.compact.resultType.isEqual("2") && this.getResult())
		this.dataSet.dataValue  = this.getDataValue();
	this.dataSet.afterRefresh();	
}

/**
 * 同步式向后台提交数据
 * @param dataSet 提交数据集
 * @param postMethod 提交后台函数
 * @return
 */
DataCompact.prototype.postData = function (dataSet,postMethod)
{
	
	if (!dataSet||!postMethod || postMethod.isEqual(""))
		return false;
	
	this.dataSet = dataSet;
	
	if (this.compact)
	{
		this.compact.setActionName(this.actionName);
		this.compact.setMethodName(postMethod);
		this.compact.setServiceCode("buss");
		this.compact.setLogID(getLogID(window));
		
		this.load = this.afterPost;
		this.httpSwitch.isSendSynch = true;	
		
		var postData = this.compact.getPost(dataSet);
		
		if (!this.compact.ispostData)
		{
			alert("无提交数据！");
			return false;
		}else{
			if (window.pageLayer)
				window.pageLayer.show();
			this.httpSwitch.send(postData);
		}
	}
}

/**
 * 同步式向后台提交数据处理
 * @return
 */
DataCompact.prototype.afterPost= function()
{
	
	this.analyzeData(this.httpSwitch.getText())
	if (this.compact.resultType.isEqual("1") && this.getResult())
		this.compact.fillDataSet(this.dataSet);
	if (this.compact.resultType.isEqual("2") && this.getResult())
		this.dataSet.dataValue  = this.getDataValue();
	
	this.dataSet.afterPost();
	
	if (window.pageLayer)
		window.pageLayer.hidden();
}

/**
 * 从后台获取数据校验
 * @param dataStr
 * @return
 */
DataCompact.prototype.analyzeData= function(dataStr)
{
	return this.compact.analyzeData(dataStr);	
}

/**
 * 从后台获取数据结果是否正确
 * @return
 */
DataCompact.prototype.getResult= function()
{
	return this.compact.isResult;
}
/**
 * 从后台获取自由格式数据
 * @return
 */
DataCompact.prototype.getDataValue= function()
{
	return this.compact.dataValue;
}
/**
 * 从后台获取数据格式
 * @return
 */
DataCompact.prototype.getResultType= function()
{
	return this.compact.resultType;
}
/**
 * 获取当前用户登录唯一标识
 * @return
 */
function getLogID(self)
{
/*	if (self.top)
	{
		if (self.top.self_logid)
		{
			return self.top.self_logid;
		}else if (self.pratentTop)
		{
			if (self.pratentTop.self_logid)
			{
				return self.pratentTop.self_logid;
			}else
			{
				return "";
			}
		}else
			return "";
		
	}else if (self.pratentTop)
	{
		if (self.pratentTop.self_logid)
			return self.pratentTop.self_logid;
		else
			return "";
	}else
		return "";*/
	
	return "";
}

